package com.tanhua.server.controller;

import com.tanhua.domain.vo.AnswerItemVo;
import com.tanhua.domain.vo.QueryQuestionBook;
import com.tanhua.domain.vo.QueryReportVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {


    @Autowired
    private TestSoulService testSoulService;



    /**
     * 测灵魂-提交问卷
     *
     * @return
     */
    @PostMapping
    public ResponseEntity<Object> queryQuizBooks(@RequestBody Map<String,List<AnswerItemVo>> answerItem) {
        List<AnswerItemVo> answers = answerItem.get("answers");
        String reportId = testSoulService.querySubmitQuiz(answers).toString();
        return ResponseEntity.ok(reportId);
    }

    /**
     * 测灵魂-查询问卷列表
     * @return
     */
    @GetMapping
    public ResponseEntity<Object> queryBookList() {
        List<QueryQuestionBook> vo = testSoulService.queryBookList();
        return ResponseEntity.ok(vo);
    }

    /**
     * 根据报告id查询报告结果
     * @param reportId
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity<Object> queryReport(@PathVariable("id")Integer reportId){
        QueryReportVo queryReport = testSoulService.queryReport(reportId);
        return ResponseEntity.ok(queryReport);
    }
}
